class LuckyTicket
  def initialize(number)
    @number = number
    @ticket_number = nil
  end
  
  def to_ticket_number
    @ticket_number ||= "%06d" % @number
  end
  
  def left
    to_ticket_number[0..2]
  end
  
  def right
    to_ticket_number[3..5]
  end
  
  def sum(digits)
    sum = 0
    digits.split(//).each{|d|  sum += d.to_i }
    sum
  end
  
  def lucky?
    sum(left) == sum(right)
  end
end

